var events=require("events");
var EventEmitter=events.EventEmitter;
function Dog(name,energy){
    EventEmitter.call(this);
    this.name=name;
    this.energy=energy;
    var intervalId=setInterval(()=>{
        if(this.energy>=0){
            this.emit('bark');
            this.energy--;
        }
        else{
            clearInterval(intervalId);
        }
    },1000)
}
for(var i in EventEmitter.prototype){
    Dog.prototype[i]=EventEmitter.prototype[i];
}
module.exports=Dog;